<%-- 
    Document   : home
    Created on : 03.Nis.2010, 18:00:51
    Author     : mkafkas
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
         <link rel="stylesheet" type="text/css" href="jMaxInput/css/style.css" media="screen"/>
         <link rel="stylesheet" type="text/css" href="styles/style.css" media="screen"/>
         <script src="http://static.ak.connect.facebook.com/connect.php/en_US" type="text/javascript"></script>
         <script src="js/jquery.js" type="text/javascript"></script>
         <script src="js/jquery.MaxInput.js" type="text/javascript"></script>
         <script type="text/javascript">
             FB.init("696f62581a6a09ac5b17357f326fd399", "/YapmadanOlme/xd_receiver.htm" );

             FB.ensureInit(function() {
                 FB.Connect.get_status().waitUntilReady( function( status ) {
                 switch ( status ) {
                  case FB.ConnectState.connected:
                      initFunction();
                     break;
                  case FB.ConnectState.appNotAuthorized:
                  case FB.ConnectState.userNotLoggedIn:
                       // FB.Connect.requireSession();
                        window.location="index.jsp?err=You need to log in to see this page";
                  }
                });
             });
             $(document).ready(function(){

                    $("#wishBox").maxinput({
				position	: 'topright',
				showtext 	: false,
				limit		: 140
                    });
                    $("#btnMakewish").live("click",function(){
                        window.alert(jQuery.trim($("#txtWish").val()));
                        postWish(jQuery.trim($("#txtWish").val()));
                    });
                    $(".thumpsUp").live("click",function(){

                    });
                    $(".thumpsDown").live("click",function(){
                        window.alert("azaltılacak");
                    });
                    $(".middleUpDownWantInner").live("click",function(){
                        window.alert("want to do this");
                    });
                    $(".middleUpDownDoneInner").live("click",function(){
                        window.alert("have done this");
                    });
                    $(".middleUpDownExpand").live("click",function(){
                        window.alert("expand");
                    });
             });

             function initFunction()
             {
                 //alert("im in");
             }
             function postWish(wishText)
             {
                 var userID=FB.Connect.get_loggedInUser();
                 $.post("wishes", {wish:wishText,id:userID,type:"1"}, function(xml) {
                             var text=jQuery.trim($("#txtWish").val())
                             postWishOnDisplay(xml,text);
                             $("#txtWish").val("");
                 });
             }
             var name;
             var picUrl;
             function postWishOnDisplay(id,text)
             {
                 var api=FB.Facebook.apiClient;
                 var userID=FB.Connect.get_loggedInUser();
                 api.fql_query("SELECT name,pic_square FROM user WHERE uid="+userID,
                           function(rows){
                                name=rows[0].name;
                                picUrl=rows[0].pic_square;
                                
                                var userID=FB.Connect.get_loggedInUser();
                                var newWishDiv=$(document.createElement('div')).attr('id',id+"_"+userID).attr('class','wishItem');
                                var currentTime = new Date();
                                var month = currentTime.getMonth() + 1;
                                var day = currentTime.getDate();
                                var year = currentTime.getFullYear();
                                var hours = currentTime.getHours();
                                var minutes = currentTime.getMinutes();
                                if (minutes < 10){
                                    minutes = "0" + minutes;
                                }
                                if (hours < 10)
                                {
                                    hours="0"+hours;
                                }
                                html='<div class="leftUp">'+
                                        '<img src="'+picUrl+'" alt="profile" />'+
                                    '</div>'+
                                    '<div class="middleUp">'+
                                       '<div class="middleUpUp">'+
                                            '<a href="profile.jsp?pid='+userID+'">'+name+'</a>'+
                                       '</div>'+
                                       '<div class="middleUpDown">'+text+
                                           '<div class="middleUpDownDate">'+
                                               day+'.'+month+'.'+year+'  '+hours+':'+minutes+
                                            '</div>'+
                                            '<div class="middleUpDownWant">'+
                                               '<div class="middleUpDownWantInner">+ I want to do this</div>'+
                                            '</div>'+
                                            '<div class="middleUpDownDone">'+
                                                '<div class="middleUpDownDoneInner">+ I have done this</div>'+
                                            '</div>'+
                                            '<div class="middleUpDownExpand"> +Expand</div>'+
                                        '</div>'+
                                     '</div>'+
                                     '<div class="rightDown">'+
                                        '<div class="rightDownDown">'+
                                            '<div class="thumpTable">'+
                                                 '<div class="thumpTableInner">'+
                                                    '<div class="thumpsUp">'+
                                                        '<img src="images/plus.jpg" />'+
                                                    '</div>'+
                                                    '<div class="numbersUp">0</div>'+
                                                    '<div class="thumpsDown">'+
                                                        '<img src="images/minus.jpg" />'+
                                                    '</div>'+
                                                    '<div class="numbersDown">0</div>'+
                                                 '</div>'+
                                             '</div>'+
                                         '</div>'+
                                      '</div>';

                                     newWishDiv.html(html);
                                     $("#homeWishList").prepend(newWishDiv);
                                     $("#"+id+"_"+userID).hide().fadeIn(1000);

                           });
             }

             function incrementThumbUp(div)
             {
                 var wishItemDivId=div.parent().parent().parent().parent().parent().attr("id");
                 var wishId=wishItemDivId.split("_")[0];
                 var authorId=wishItemDivId.split("_")[1];
                 $.post("wishes", {updateType:"1",id:wishId,type:"2"}, function(xml) {
                            var likeNum=div.next().innerHTML;

                 });
             }
             
         </script>
    </head>
    <body>

        <%--  <div>Ne yapmak istiyorsunuz?</div> --%>

        <div id="wishBox" class="jMax"></div>

        <div><h1>Home</h1></div>
        <div id="homeWishList" class="wishListContainer">
            <div class="wishItem">
                <div class="leftUp">
                    <img src="http://profile.ak.fbcdn.net/v22941/1373/64/q563383238_6681.jpg" alt="profile" />
                </div>
                <div class="middleUp">
                    <div class="middleUpUp">
                        <a href="profile.jsp?pid=563383238">Mahmut Kafkas</a>
                    </div>
                    <div class="middleUpDown">
                        soahfdhkjdaksjdaksdasjda sadhasghdashdas adsdaskljdsa
                        <div class="middleUpDownDate">
                            April 7 10:04 pm
                        </div>
                        <div class="middleUpDownWant">
                            <div class="middleUpDownWantInner">+ I want to do this</div>
                        </div>
                        <div class="middleUpDownDone">
                            <div class="middleUpDownDoneInner">+ I have done this</div>
                        </div>
                        <div class="middleUpDownExpand">
                             +Expand
                        </div>
                    </div>
                </div>
                <div class='rightDown'>    
                    <div class='rightDownDown'>
                        <div class='thumpTable'>
                            <div class='thumpTableInner'>
                                <div class='thumpsUp'>
                                    <img src='images/plus.jpg' />
                                </div>
                                <div class='numbersUp'>10</div>
                                <div class='thumpsDown'>
                                    <img src='images/minus.jpg' />
                                </div>
                                <div class='numbersDown'>6</div>
                            </div>
                        </div>
                    </div>
                </div>
                
            </div>
        </div>
    </body>
</html>
